#!/usr/bin/python


class ConflictReason(object):

  def __init__(self, index, description):
    self.index = index
    self.description = description


class SolutionLog(object):

  def __init__(self):
    # Logs reasons why constraints were not satisfied.
    self._conflict_reasons = []
    self._conflict_counts = []

  def CreateConflictReason(self, reason_description):
    i = len(self._conflict_reasons)
    c = ConflictReason(i, reason_description)
    self._conflict_reasons.append(c)
    self._conflict_counts.append(self.CreateConflictRecord())
    return c

  def CreateConflictRecord(self):
    pass

  def LogConflict(self, reason, shift, doctor):
    pass

  def Conflicts(self):
    """Returns conflicts logged.

    Returns:
      List of descriptions and locality: [description, [(shift, doctor)*]]
    """
    return [(r.description, c) for (r, c) in
        zip(self._conflict_reasons, self._conflict_counts)]


class CoarseSolutionLog(SolutionLog):

  def __init__(self):
    SolutionLog.__init__(self)

  def CreateConflictRecord(self):
    return 0

  def LogConflict(self, reason, shift, doctor):
    self._conflict_counts[reason.index] += 1


class FineSolutionLog(SolutionLog):

  def __init__(self):
    SolutionLog.__init__(self)

  def CreateConflictRecord(self):
    return []

  def LogConflict(self, reason, shift, doctor):
    self._conflict_counts[reason.index].append((shift, doctor))
